<?php

/**
* @copyright   (C) 2010 iJoomla, Inc. - All rights reserved.
* @license  GNU General Public License, version 2 (http://www.gnu.org/licenses/gpl-2.0.html) 
* @author  iJoomla.com webmaster@ijoomla.com
* @url   http://www.ijoomla.com/licensing/
* the PHP code portions are distributed under the GPL license. If not otherwise stated, all images, manuals, cascading style sheets, and included JavaScript  
* are NOT GPL, and are released under the IJOOMLA Proprietary Use License v1.0 
* More info at http://www.ijoomla.com/licensing/
*/

defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.view');

class iJoomla_SurveysViewNewquestion extends JView {
	
	function display($tpl = null){				
		JToolBarHelper::title(JText::_('COM_SURVEYS_SURVEY'));
		JToolBarHelper::save();
		JToolBarHelper::apply();
		JToolBarHelper::cancel();
		JToolBarHelper::divider();
		JToolBarHelper::help('com_surveys',true);
					
		$this->values = $this->get("QuestionValues");
		$this->columnsValues = $this->get("ColumnsValues");	
		$this->params = $this->get("Params");			
			
		parent::display($tpl);	
	}
		
	function getSurveysList($default, $page_id){
		$result = $this->get("AllSurveys");
		$selected = "";
		$return = '<select name="survey_id" id="survey_id" onchange="changeSurvey(this, \''.$page_id.'\');">';
		$return .= "<option value=\"0\">-- ".JText::_("COM_SURVEYS_SELECT_SURVEY_FROM_LIST")." --</option>";
		foreach($result as $key=>$value){
			$selected = "";
			if($value["id"] == $default){
				$selected = ' selected="selected" '; 
			}
			$return .= "<option value=\"".$value["id"]."\" ".$selected." >".$value["title"]."</option>";			
		}
		$return .= "</select>";
		return $return;
	}
	
	function getPageList($default){
		$result = $this->get("AllPages");
		$return = '<select name="page_id" id="page_id">';
		$selected = "";
		foreach($result as $key=>$value){
			$selected = "";
			if($value["id"] == $default){
				$selected = ' selected="selected" '; 
			}
			$return .= "<option value=\"".$value["id"]."\" ".$selected." >".$value["title"]."</option>";			
		}
		$return .= "</select>";
		return $return;
	}
	
	function getQuestionType($default){
		$selected = "";
		if($default == "0"){
			$selected = ' selected="selected" ';
		}
		$return  = '<select name="question_type" onchange="selectQuestion(this);" id="question_type">';
		$return .= 		'<option value="0" '.$selected.' >-- '.JText::_("COM_SURVEYS_SELECT_QUESTION_TYPE").' --</option>';
		$selected = "";
		if($default == "1"){
			$selected = ' selected="selected" ';
		}
		$return .= 		'<option value="1" '.$selected.' >'.JText::_("COM_SURVEYS_CHOICE_ONE_ANSWER_VERTICAL").'</option>';
		$selected = "";
		if($default == "2"){
			$selected = ' selected="selected" ';
		}
		$return .= 		'<option value="2" '.$selected.' >'.JText::_("COM_SURVEYS_CHOICE_ONE_ANSWER_HORIZONTAL").'</option>';
		$selected = "";
		if($default == "3"){
			$selected = ' selected="selected" ';
		}
		$return .= 		'<option value="3" '.$selected.' >'.JText::_("COM_SURVEYS_CHOICE_ONE_ANSWER_MENU").'</option>';
		$selected = "";
		if($default == "4"){
			$selected = ' selected="selected" ';
		}
		$return .= 		'<option value="4" '.$selected.' >'.JText::_("COM_SURVEYS_CHOICE_MULTIPLE_ANSWER_VERTICAL").'</option>';
		$selected = "";
		if($default == "5"){
			$selected = ' selected="selected" ';
		}
		$return .= 		'<option value="5" '.$selected.' >'.JText::_("COM_SURVEYS_CHOICE_MULTIPLE_ANSWER_HORIZONTAL").'</option>';
		$selected = "";
		if($default == "6"){
			$selected = ' selected="selected" ';
		}
		$return .= 		'<option value="6" '.$selected.' >'.JText::_("COM_SURVEYS_MATRIX_ONE_ANSWER_PER_ROW").'</option>';
		$selected = "";
		if($default == "7"){
			$selected = ' selected="selected" ';
		}
		$return .= 		'<option value="7" '.$selected.' >'.JText::_("COM_SURVEYS_MATRIX_MULTIPLE_ANSWER_PER_ROW").'</option>';
		$selected = "";
		if($default == "8"){
			$selected = ' selected="selected" ';
		}
		$return .= 		'<option value="8" '.$selected.' >'.JText::_("COM_SURVEYS_MATRIX_MULTIPLE_ANSWER_PER_ROW_MENUS").'</option>';
		$selected = "";
		if($default == "9"){
			$selected = ' selected="selected" ';
		}
		$return .= 		'<option value="9" '.$selected.' >'.JText::_("COM_SURVEYS_OPEN_ENDED_ONE_LINE_W_PROMPT").'</option>';
		$selected = "";
		if($default == "10"){
			$selected = ' selected="selected" ';
		}
		$return .= 		'<option value="10" '.$selected.' >'.JText::_("COM_SURVEYS_OPEN_ENDED_ONE_MORE_LINE_W_PROMPT").'</option>';
		$selected = "";
		if($default == "11"){
			$selected = ' selected="selected" ';
		}
		$return .= 		'<option value="11" '.$selected.' >'.JText::_("COM_SURVEYS_OPEN_ENDED_ESSAY").'</option>';
		$selected = "";
		if($default == "12"){
			$selected = ' selected="selected" ';
		}
		$return .= 		'<option value="12" '.$selected.' >'.JText::_("COM_SURVEYS_OPEN_ENDED_CONSTANT_SUM").'</option>';
		$selected = "";
		if($default == "13"){
			$selected = ' selected="selected" ';
		}
		$return .= 		'<option value="13" '.$selected.' >'.JText::_("COM_SURVEYS_OPEN_ENDED_DATE_AND_OR_TIME").'</option>';
		$return .= '</select>';
		
		return $return;
	}
	
	function getMenusNumber($nums_menu_heading){
		$selected = "";
		$return = '<select name="nums_menu_heading" onchange="printMenus(this);">';
		if($nums_menu_heading == ""){
			$selected = ' selected="elected" ';
		}
		$return .= '<option value="0" '.$selected.' >-- '.JText::_("COM_SURVEYS_SELECT_MENU_NUMBER").' --</option>';
		for($i=1; $i<=10; $i++){
			$selected = "";
			if($nums_menu_heading == $i){
				$selected = ' selected="elected" ';
			}
			$return .= '<option value="'.$i.'" '.$selected.'>'.$i.'</option>';
		}
		$return .= '</select>';
		return $return;
	}
	
	function printMenusList($number){
		$return = "";
		$id = JRequest::getVar("id", "0");
		$model =& $this->getModel();
        		
		for($i=1; $i<=10; $i++){
			$display = "none";
			if($i <= $number){
				$display = "block";
			}
			$heading = "";
			$choises = "";
			
			if($id != "0"){			
				$result = $model->getMenuDetails($id, $i);
				if(isset($result["0"]["heading"])){
					$heading = $result["0"]["heading"];
				}
				if(isset($result["0"]["menu_choises"])){
					$choises = $result["0"]["menu_choises"];
					$choises = str_replace('"', "&quot;", $choises);
				}	
			}
			$heading = str_replace('"', "&quot;", $heading);
			$return .= "<tr>";
			$return .= 		"<td>";
			$return .= 			'<div style="display:'.$display.';" id="menu_chois_'.$i.'">';
			$return .= 				"<b>".JText::_("COM_SURVEYS_MENU_HEADING")."</b>: ".'<input type="text" name="menu_heading['.$i.']" value="'.trim($heading).'">'."<br/>";
			$return .= 				"<b>".JText::_("COM_SURVEYS_MENU_CHOISES")."</b><br/>";
			$return .= 				'<textarea name="menu_choices['.$i.']" rows="4" cols="45">'.trim($choises).'</textarea>';
			$return .= 			"</div>";
			$return .= 		"</td>";
			$return .= "</tr>";
		}
		return $return;
	}
	
	function getOrdering($ordering){
		$pages = $this->get("Pages");
		$return = "";
		$selected = "";
		
		if(count($pages) > 0){
			$return .= "<select name=\"ordering\">";			
			if($ordering == 0){
				$selected = ' selected="selected" ';
			}
			$return .= "<option value=\"0\" ".$selected.">0. ".JText::_("COM_SURVEYS_FIRST")."</option>";
			$selected = "";
			$i=1;
			foreach($pages as $key=>$value){
				$selected = "";
				if($i == $ordering){
					$selected = ' selected="selected" ';
				}
				$return .= "<option value=\"".$i."\" ".$selected.">".$i.". ".stripslashes($value["title"])."</option>";				
				$i ++;
			}
			if($ordering == "last"){
				$selected = ' selected="selected" ';
			}
			$return .= "<option value=\"".(count($pages)+1)."\"".$selected.">".(count($pages)+1).". ".JText::_("COM_SURVEYS_LAST")."</option>";
			$return .= "</select>";
		}
		
		return $return;
	}
}

?>
 